<html>
<head><meta charset="utf-8"><title>invalid register `r9` · project-inline-asm · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/index.html">project-inline-asm</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html">invalid register `r9`</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="239101801"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239101801" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239101801">(May 17 2021 at 14:44)</a>:</h4>
<blockquote>
<p>invalid register <code>r9</code>: r9 is used internally by LLVM and cannot be used as an operand for inline asm</p>
</blockquote>
<p>Lately I started getting this error in CI on some code that used to pass just fine.</p>
<p>Is <code>r9</code> <em>supposed</em> to have been invalid to use this whole time? or is this a temporary bug and i should file an issue?</p>



<a name="239125057"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239125057" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239125057">(May 17 2021 at 17:02)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/issues/85247">https://github.com/rust-lang/rust/issues/85247</a></p>



<a name="239130759"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239130759" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239130759">(May 17 2021 at 17:42)</a>:</h4>
<p>Ah, "good"</p>



<a name="239145600"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239145600" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239145600">(May 17 2021 at 19:22)</a>:</h4>
<p>This is something that really, <em>really</em> needs fixing in LLVM somehow, to make it possible to use registers that LLVM needs to architecturally reserve. That would make it safe to allow use of all registers, and let LLVM sort out whether it needs to shuffle things around to allow that.</p>



<a name="239183966"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239183966" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239183966">(May 18 2021 at 01:18)</a>:</h4>
<p>can we fix this on the rustc side until then?</p>



<a name="239210937"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239210937" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239210937">(May 18 2021 at 07:40)</a>:</h4>
<p>Theoretically. We would need a reliable code sequence that sets r9 from some input that isn't reserved while not using any more registers.</p>



<a name="239211129"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239211129" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239211129">(May 18 2021 at 07:42)</a>:</h4>
<p>So, for instance, by creating a small structure and passing the address of it. But that doesn't work for output.</p>



<a name="239211173"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239211173" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239211173">(May 18 2021 at 07:42)</a>:</h4>
<p>If this is something you care about, looking into the LLVM side would help.</p>



<a name="239250527"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239250527" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239250527">(May 18 2021 at 13:11)</a>:</h4>
<p>unfortunately this is way out of my depth, and I don't have much time for programming lately. I would like this solved, but I really have no idea where to even begin investigating anything about LLVM.</p>



<a name="239322960"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239322960" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239322960">(May 18 2021 at 20:45)</a>:</h4>
<p>Is an LLVM bug filed for this?</p>



<a name="239323128"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239323128" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239323128">(May 18 2021 at 20:46)</a>:</h4>
<p>You should probably just fix your asm code to use a different register, or move some other register into <code>r9</code>.</p>



<a name="239323163"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239323163" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239323163">(May 18 2021 at 20:46)</a>:</h4>
<p>ARM specifies <code>r9</code> as a platform-reserved register, which portable assembly code should avoid using.</p>



<a name="239323646"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239323646" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239323646">(May 18 2021 at 20:49)</a>:</h4>
<p><span class="user-mention silent" data-user-id="143274">Amanieu</span> <a href="#narrow/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60/near/239323163">said</a>:</p>
<blockquote>
<p>ARM specifies <code>r9</code> as a platform-reserved register, which portable assembly code should avoid using.</p>
</blockquote>
<p>Not everyone is using <code>asm!</code> to make "portable assembly", whatever <em>that</em> means.</p>



<a name="239328211"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239328211" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239328211">(May 18 2021 at 21:22)</a>:</h4>
<p><span class="user-mention silent" data-user-id="143274">Amanieu</span> <a href="#narrow/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60/near/239323128">said</a>:</p>
<blockquote>
<p>You should probably just fix your asm code to use a different register, or move some other register into <code>r9</code>.</p>
</blockquote>
<p>That isn't necessarily always an option. I can't speak to ARM r9, but x86 ebx <em>is</em> absolutely used in existing code.</p>



<a name="239328224"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239328224" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239328224">(May 18 2021 at 21:22)</a>:</h4>
<p>Sometimes you don't get a choice on which register you use.</p>



<a name="239328510"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239328510" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239328510">(May 18 2021 at 21:25)</a>:</h4>
<p>My understanding is that the impact on Arm is mostly that the reservation in LLVM and for Arm is based on whether or not certain kinds of applications are being compiled, with certain kinds of functions, which is likely to be the least true for comparatively resource-constrained early-Arm embedded chips, which don't have the abundance of registers + vector registers that more recent examples may enjoy.</p>



<a name="239328528"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239328528" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239328528">(May 18 2021 at 21:25)</a>:</h4>
<p>and if you're using load multi / store multi to copy data around then you run low on registers if you arbitrarily can't use r9 in addition to the others you already can't use</p>



<a name="239328688"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239328688" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239328688">(May 18 2021 at 21:26)</a>:</h4>
<p>I mean, if you're writing asm for aarch64 and find out a register is reserved, of course you just shrug and go "hey whatever man, I got, what, 60 of these lying around if you count the vector registers?"</p>



<a name="239329140"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239329140" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239329140">(May 18 2021 at 21:30)</a>:</h4>
<p>well, as far as frame pointers are concerned, they are usually expected to remain reserved for unwinding and/or debuggers to work.</p>



<a name="239329223"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239329223" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239329223">(May 18 2021 at 21:31)</a>:</h4>
<p>so they are not reserved for the compiler reasons, but rather for platform reasons (i.e. OS and tooling used within that OS can rely on it)</p>



<a name="239329721"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239329721" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239329721">(May 18 2021 at 21:35)</a>:</h4>
<p>That is true but an OS is not always involved.</p>



<a name="239329902"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239329902" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239329902">(May 18 2021 at 21:36)</a>:</h4>
<p>Holds true for debuggers still. But yeah, you won't be using rwpi nor framepointers most likely in embedded.</p>



<a name="239330234"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239330234" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239330234">(May 18 2021 at 21:39)</a>:</h4>
<p>i forget if the thumbv4t-none-eabi target omits the frame pointer</p>



<a name="239330335"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239330335" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239330335">(May 18 2021 at 21:40)</a>:</h4>
<p>i suppose it should, or another target should be added if it can't</p>



<a name="239330717"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239330717" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239330717">(May 18 2021 at 21:44)</a>:</h4>
<p>LLVM may still use a frame pointer even if you have disabled it. This typically happens if stack realignment is needed (e.g. you have a 64-byte aligned local).</p>



<a name="239330769"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239330769" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239330769">(May 18 2021 at 21:44)</a>:</h4>
<p>The thing is, due to inlining and other optimizations, we can't know in advance whether the frame pointer will be reserved or not. So we conservatively always mark it as reserved.</p>



<a name="239330823"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239330823" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239330823">(May 18 2021 at 21:45)</a>:</h4>
<p>Anyways, regarding <code>r9</code> all you need to do is push/pop it around your asm code.</p>



<a name="239331213"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239331213" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239331213">(May 18 2021 at 21:48)</a>:</h4>
<p>so why doesn't the inline asm machinery do that automatically if r9 is used?</p>



<a name="239338479"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239338479" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239338479">(May 18 2021 at 22:59)</a>:</h4>
<p><span class="user-mention" data-user-id="224471">@Lokathor</span> That's part of what I was getting at when I suggested "a reliable code sequence that sets r9 from some input that isn't reserved while not using any more registers".</p>



<a name="239338504"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239338504" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239338504">(May 18 2021 at 22:59)</a>:</h4>
<p>You'd have to have something we could automatically add to the start and end of assembly blocks for inputs/outputs in that register (respectively) that would read/write it from memory somehow.</p>



<a name="239338604"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239338604" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239338604">(May 18 2021 at 23:00)</a>:</h4>
<p>We discussed this in a topic some time ago, but the conclusion was that if we did so, we might rule out the possibility of memory operands in the future.</p>



<a name="239338637"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239338637" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239338637">(May 18 2021 at 23:00)</a>:</h4>
<p>All that said, patch and test cases welcome. :)</p>



<a name="239339014"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239339014" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239339014">(May 18 2021 at 23:03)</a>:</h4>
<p>in this case, it's that r9 is trashed by the asm, but not an input or output value: <a href="https://github.com/rust-console/gba/blob/main/src/sync/statics.rs#L88">https://github.com/rust-console/gba/blob/main/src/sync/statics.rs#L88</a></p>



<a name="239339164"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239339164" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239339164">(May 18 2021 at 23:04)</a>:</h4>
<p>If it's <em>just</em> a clobber, we could probably handle that by just inserting a push/pop ourselves.</p>



<a name="239339190"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239339190" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239339190">(May 18 2021 at 23:05)</a>:</h4>
<p><span class="user-mention" data-user-id="143274">@Amanieu</span> Does it seem potentially reasonable to allow clobbers of reserved registers and handle them by pushing/popping ourselves?</p>



<a name="239339226"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239339226" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239339226">(May 18 2021 at 23:05)</a>:</h4>
<p>That's separate from handling those registers as inputs or outputs.</p>



<a name="239343605"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239343605" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239343605">(May 18 2021 at 23:54)</a>:</h4>
<p>That doesn't solve the issue of ruling out the possibility of supporting memory operands in the future.</p>



<a name="239347993"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239347993" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239347993">(May 19 2021 at 00:49)</a>:</h4>
<p>...are memory operands a thing on Arm? or am I misunderstanding "memory operands" when it is a term of art?</p>



<a name="239352181"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239352181" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239352181">(May 19 2021 at 01:48)</a>:</h4>
<p>Yeah, memory operands refers to <code>"m"</code> input/output constraint in llvm/gcc-style inline asm.</p>



<a name="239352671"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239352671" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239352671">(May 19 2021 at 01:54)</a>:</h4>
<p><span class="user-mention silent" data-user-id="143274">Amanieu</span> <a href="#narrow/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60/near/239343605">said</a>:</p>
<blockquote>
<p>That doesn't solve the issue of ruling out the possibility of supporting memory operands in the future.</p>
</blockquote>
<p>You're concerned about stack-relative memory operands being invalidated by a push/pop?</p>



<a name="239355662"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239355662" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239355662">(May 19 2021 at 02:30)</a>:</h4>
<p>also register-relative memory operands using <code>r9</code> (or any other register llvm doesn't know we're modifying) as the base address.</p>



<a name="239358173"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239358173" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239358173">(May 19 2021 at 03:03)</a>:</h4>
<p>So I guess the basic requirement or user story or whatever is (approximately) "i want scratch registers and i know that the compiler can do this somehow, let me assert something or other so i can grab up as many scratch registers as possible".</p>
<p>so maybe this can be some sort of option entry you can pass in to get the compiler to play along?</p>



<a name="239463309"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239463309" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239463309">(May 19 2021 at 17:19)</a>:</h4>
<p>I think there are multiple concerns here. Wanting a reserved register as a scratch register is one issue. Wanting a reserved register because you need <em>that specific register</em> to match some particular interface is another.</p>



<a name="239463327"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239463327" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239463327">(May 19 2021 at 17:19)</a>:</h4>
<p>Both are completely valid; they may have different solutions.</p>



<a name="239463442"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239463442" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239463442">(May 19 2021 at 17:20)</a>:</h4>
<p>But in any case, an opt-in along the lines of "I need reserved registers and I understand that means I might not be allowed memory operands in the future" would be appealing.</p>



<a name="239466097"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239466097" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239466097">(May 19 2021 at 17:37)</a>:</h4>
<p>Why not just do the push/pop yourself in that case? Since you'd have to opt-in anyways.</p>



<a name="239468070"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239468070" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239468070">(May 19 2021 at 17:51)</a>:</h4>
<p>It'd be more complex to handle things like input and output shuffling (which we could also do if we don't worry about memory operands).</p>



<a name="239468468"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239468468" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239468468">(May 19 2021 at 17:53)</a>:</h4>
<p>I'd like to be able to do things like an <code>asm!</code> with every single register as an <code>inout</code>, for instance.</p>



<a name="239468592"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239468592" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239468592">(May 19 2021 at 17:54)</a>:</h4>
<p>That's just going make LLVM error due to a lack of registers.</p>



<a name="239468659"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239468659" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239468659">(May 19 2021 at 17:54)</a>:</h4>
<p>Because of the reserved register handling, or something else?</p>



<a name="239468721"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239468721" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239468721">(May 19 2021 at 17:55)</a>:</h4>
<p>If you try to allocate every single register with <code>inout</code>.</p>



<a name="239469146"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239469146" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239469146">(May 19 2021 at 17:57)</a>:</h4>
<p>What if we internally translated the reserved registers to stuff them in a struct and move it into and out of the reserved registers in added assembly?</p>



<a name="239469589"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239469589" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239469589">(May 19 2021 at 18:00)</a>:</h4>
<p>My main motivation here is that I'd like <code>asm!</code> with registers like x86 rbx or arm r9 to work as automatically as it does in GCC <code>__asm__</code> (which just doesn't stop you from using those at all, and as far as I can tell just saves/restores them around your assembly if it's using them itself).</p>



<a name="239469631"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239469631" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239469631">(May 19 2021 at 18:01)</a>:</h4>
<p>And, of course, if you don't use whatever compilation options enable the use of those registers then you can use them freely.</p>



<a name="239492687"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239492687" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239492687">(May 19 2021 at 20:42)</a>:</h4>
<p>yeah i wanted <code>out("r9") _</code>, which seems <em>pretty flexible</em>, and rustc/llvm should be able to compensate if necessary</p>



<a name="239492798"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/invalid%20register%20%60r9%60/near/239492798" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/invalid.20register.20.60r9.60.html#239492798">(May 19 2021 at 20:43)</a>:</h4>
<p>I'm being deliberately conservative with the reserved registers for the initial stabilization. We can always relax the constraints later.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>